const { Serverlet } = require('./serverlet')
const url = require('url')
const querystring = require('querystring')

class func1 extends Serverlet {
  constructor (req, res) {
    super(req, res)
  }

  get (req, res) {
    let result = {
      code: 200,
      msg: '请求成功',
      method: 'GET',
      detail: '来自func1'
    }
    res.setHeader('Content-Type', 'application/json;charset=utf8')
    res.end(JSON.stringify(result))
  }

  post (req, res) {
    let post = ''
    req.on('data', function (chunk) {
      post += chunk
    })
    req.on('end', function () {
      let obj = querystring.parse(post)
      let result = {
        code: 200,
        msg: '请求成功,name' + obj.name,
        method: 'POST',
        detail: '来自func1'
      }
      res.setHeader('Content-Type', 'application/json;charset=utf8')
      res.end(JSON.stringify(result))
    })
  }
}

module.exports = {
  func1,
}
